<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Basic_library
{
	// Protected or private properties
	protected $_table;
	
	// Constructor
	public function __construct()
	{
		if (!isset($this->CI))
		{
			$this->CI =& get_instance();
		}
		
		$this->_table = $this->CI->config->item('database_tables');
	}
		
	// Public methods
	
	public function get_category_name($id=null)
	{
		
		$this->CI->db->select('id, name');
		$this->CI->db->from('site_category');		
		$this->CI->db->where('id',$id);		
		$query = $this->CI->db->get();
			
		if ($query->num_rows() > 0)
		{			
			$return = $query->result_array();
		}
		else
		{
			return null;
		}
		
		if(is_array($return))
		{
			return $return[0]['name'];
		}
		return null;
	}
	
	public function get_categories_name($id=null, $alias = null)
	{
		
		$this->CI->db->select('id, name, alias');
		$this->CI->db->from('site_category');		
		$this->CI->db->where('id',$id);
		$this->CI->db->or_where('alias',$alias);		
		//$this->CI->db->where("(id = '" . $id . "' OR alias = '" . $alias . "')");		
		$query = $this->CI->db->get();
			
		if ($query->num_rows() > 0)
		{			
			$return = $query->result_array();
		}
		else
		{
			return null;
		}
		
		if(is_array($return))
		{
			return $return[0]['name'];
		}
		return null;
	}
	
	public function get_category_id($alias = null)
	{
		
		$this->CI->db->select('id, alias');
		$this->CI->db->from('site_category');		
		$this->CI->db->where('alias',$alias);		
		//$this->CI->db->where("(id = '" . $id . "' OR alias = '" . $alias . "')");		
		$query = $this->CI->db->get();
			
		if ($query->num_rows() > 0)
		{			
			$return = $query->result_array();
		}
		else
		{
			return null;
		}
		
		if(is_array($return))
		{
			return $return[0]['id'];
		}
		return null;
	}
	
	public function get_category_info($id = null, $alias = null)
	{
		
		$this->CI->db->select('id, alias, name, description');
		$this->CI->db->from('site_category');		
		$this->CI->db->where('id',$id);
		$this->CI->db->or_where('alias',$alias);		
		$query = $this->CI->db->get();
			
		if ($query->num_rows() > 0)
		{			
			$return = $query->result_array();
		}
		else
		{
			return null;
		}
		
		if(is_array($return))
		{
			return $return[0];
		}
		return null;
	}
	
	public function get_categories_alias($id=null)
	{
		
		$this->CI->db->select('*');
		$this->CI->db->from('site_category');		
		$this->CI->db->where('id',$id);		
		$query = $this->CI->db->get();
			
		if ($query->num_rows() > 0)
		{			
			$return = $query->result_array();
		}
		else
		{
			return null;
		}
		
		if(is_array($return))
		{
			return $return[0]['alias'];
		}
		return null;
	}
	
	
	
	public function get_article_title($id=null)
	{
		
		$this->CI->db->select('id, description, title');
		$this->CI->db->from('site_content');		
		$this->CI->db->where('id',$id);		
		$query = $this->CI->db->get();
			
		if ($query->num_rows() > 0)
		{			
			$return = $query->result_array();
		}
		else
		{
			return null;
		}
		
		if(is_array($return))
		{
			return $return[0];
		}
		return null;
	}
	
	
	
	
	public function get_developer_name($id=null)
	{
		
		$this->CI->db->select('*');
		$this->CI->db->from('user');		
		$this->CI->db->where('id',$id);		
		$query = $this->CI->db->get();
			
		if ($query->num_rows() > 0)
		{			
			$return = $query->result_array();
		}
		else
		{
			return null;
		}
		
		if(is_array($return))
		{
			return $return[0]['username'];
		}
		return null;
	}
	
	
	
	public function get_group_name($id=null)
	{
		
		$this->CI->db->select('*');
		$this->CI->db->from('role');		
		$this->CI->db->where('role_id',$id);		
		$query = $this->CI->db->get();
			
		if ($query->num_rows() > 0)
		{			
			$return = $query->result_array();
		}
		else
		{
			return null;
		}
		
		if(is_array($return))
		{
			return $return[0]['role_name'];
		}
		return null;
	}
	
	
	
}

/* End of file Categories_library.php */
/* Location: ./application/libraries/Basic_library.php */